package com.falm.generator;

import com.falm.entity.MainTemplateConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * @author Administrator
 */
public class MainGenerator {
    public static final Logger logger = LoggerFactory.getLogger(MainGenerator.class);

    public static void doGenerate(MainTemplateConfig config) {
        String projectDir = System.getProperty("user.dir");
        String inputPath = projectDir + File.separator + "example" + File.separator + "acm-template";
        Map<String, String> generateMap = StaticGenerator.doGenerator(inputPath, projectDir + File.separator);


        generateMap.forEach((key, value) -> {
            try {
                // 确保输出目录存在
                File outputDir = new File(value);
                if (!outputDir.exists()) {
                    boolean created = outputDir.mkdirs();
                    if (!created) {
                        System.err.println("无法创建目录: " + value);
                        return;
                    }
                }
                DynamicGenerator.doGenerator(config, key, value);
            } catch (IOException e) {
                logger.error(e.getLocalizedMessage());
            }
        });
    }
}
